﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using EC_DataBase;
using System.Data;

namespace EasyCheque.User
{
    public partial class CertificateInfo : System.Web.UI.Page
    {
        private void readDataFromDB()
        {
            DataSet infoHere = new DataSet();
            if (Session["uid"] == null)
            {
                Response.Redirect("~/Default.aspx");
            }
            string CmdStr = @"SELECT C_ID,REG_TIME,STATE FROM CERTIFICATES WHERE [STATE]=TRUE AND  PID=" + Session["uid"].ToString();
            infoHere = Logic.Logic.QueryData(CmdStr);
            if (infoHere != null)
            {
                TextBox_C_ID.Text = infoHere.Tables[0].Rows[0][0].ToString();
                //TextBox_PUB_KEY.Text = infoHere.pub_key;
                TextBox_REGTIME.Text = infoHere.Tables[0].Rows[0][1].ToString();
                TextBox_STATE.Text = infoHere.Tables[0].Rows[0][2].ToString();

                if (TextBox_STATE.Text == "True")
                {
                    TextBox_STATE.ForeColor = System.Drawing.Color.Green;
                    TextBox_STATE.Text = "正常";
                }
                else
                {
                    TextBox_STATE.ForeColor = System.Drawing.Color.Red;
                    TextBox_STATE.Text = "无效";
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            // 界面处理。
            Panel_Calendar.Style["display"] = "none";
            Panel_Calendar.Style["position"] = "absolute";

            // 控件内容填充。
            // 从数据库中读出数据。
            readDataFromDB();
            // ~
        }

        protected void Calendar_InPanel_SelectionChanged(object sender, EventArgs e)
        {
            TextBox_REGTIME.Text = Calendar_InPanel.SelectedDate.ToString("yyyy-MM-dd");
        }

        protected void Calendar_InPanel_VisibleMonthChanged(Object sender, MonthChangedEventArgs e)
        {
            Panel_Calendar.Style["display"] = "";
        }

        protected void Button_ChangeCertificate_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Person/ApplyForCertificate_Internal.aspx");
        }
    }
}
